<?php require_once('../../includes/spip_launcher.php'); ?>

$(document).ready(function() {
        insert_index = 0;
	   $('.list_form .add_field_button').click(function(){
	       var container = $('.list_form .elements_container');
	       var content = '<tr>';
            content += '<td>';
            content += '?';    
            content += '</td>';            
            content += '<td>';
            
            // Inputs for insert here
            content += '<input type="text" name="elements_insert['+insert_index+'][titre]" value="" style="width: 340px;" />';
            content += '<input type="hidden" name="elements_insert['+insert_index+'][id_propriete]" value="<?php echo($_REQUEST['id_propriete']); ?>" />';
            
            content += '</td>';            
            content += '<td>';
            
            content += '<input type="text" name="elements_insert['+insert_index+'][id_mot]" value="" style="width: 20px;" />';
            
            insert_index++;
            content += '</td>';
            content += '<td><a href="javascript:;" class="delete_link"><?php echo(_T('ecatalogue:delete')); ?></a></td>';
            content += '</tr>';
           container.append(content);
	   });
       
       $('.list_form .delete_link').live('click', function(){
            if (confirm('<?php echo(_T('ecatalogue:delete_element')); ?> "' + $(this).parent().prev().find('input').val() + '"?')) {                
                var element_id = $(this).attr('data-element-id');
                if (element_id!=undefined) {                                     
                    $('.list_form').append('<input type="hidden" name="elements_delete['+element_id+']" value="'+element_id+'" />');    
                }
                $(this).parent().parent().remove();    
            }                
       });
       
       $('.list_form select#id_groupe').change(function(){
            window.location.replace('<?php echo $GLOBALS['meta']['adresse_site']; ?>/ecrire/?exec=ecatalogue_options&id_groupe='+$("#id_groupe").find('option:selected').val());
       });
        $('.list_form select#id_propriete').change(function(){
            window.location.replace('<?php echo $GLOBALS['meta']['adresse_site']; ?>/ecrire/?exec=ecatalogue_options&id_groupe='+$("#id_groupe").find('option:selected').val()+'&id_propriete='+$("#id_propriete").find('option:selected').val());
        });
       $('.reponse_formulaire').delay(3000).fadeOut();
});